package com.stylefeng.guns.modular.system.dao;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.modular.system.model.SysDict;
import org.springframework.cache.annotation.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 
 * 系统字典表 Mapper 接口 
 * @author 张亚林
 * @Date 2018-10-30 17:07
 */
@Repository
@CacheConfig(cacheNames ="local")
public interface SysDictMapper extends BaseMapper<SysDict> {
    /**
     * 删除系统字典表
     * @param  sysDict
     * @return    
     */
    @CacheEvict(key="'sysDict_'+#sysDict.id",allEntries=true ,beforeInvocation=true)
    int deleteSysDict(SysDict sysDict)throws Exception;
    /**
     * 批量系统字典表
     * @param ids 主键id数组
     * @return     
     */
    @CacheEvict(key="'sysDict_'+#p0",allEntries=true,beforeInvocation=true)
    int deleteBatchSysDict(String[] ids)throws Exception;
    /**
     * 查询系统字典表列表
     * @param sysDict 系统字典表对象
     * @return
     *
     */
    @Caching(
        cacheable = {
    @Cacheable(key = "'sysDict_'+#root.methodName",unless="#result == null")},
        put = {
               @CachePut(key = "'sysDict_'+#p0.code", unless = "#result != null"),
               @CachePut(key = "'sysDict_'+#p0.pid", unless = "#result != null")
        })
    List<SysDict> selectListSysDict(SysDict sysDict)throws Exception;
    /**
     * 分页查询系统字典表列表
     * @param page  分页对象
     * @param sysDict 系统操作对象
     * @return
     * @Date 2018-10-02
     */
    @Caching(
            cacheable = {
    @Cacheable(key = "'sysDict_'+#page.current+'_'+#page.size+'_'+#sysDict.code", condition = "#result.size() > 0",unless="#result == null")},
            put = {
                    @CachePut(key = "'sysDict_'+#p1.code", condition = "#result != null"),
                    @CachePut(key = "'sysDict_'+#p1.pid", condition = "#result != null")
            })
    List<SysDict> selectListSysDict(Page page, SysDict sysDict)throws Exception;


    /**
     * 同一个事务 互斥锁查询
     * @param sysDict 系统操作对象
     * @return     
     */
    @Caching(
            cacheable = {
                    @Cacheable(key = "'sysDict_'+#sysDict.code", condition = "#result.size() > 0",unless="#result == null")},
            put = {
                    @CachePut(key = "'sysDict_'+#p0.code", condition = "#result != null"),
                    @CachePut(key = "'sysDict_'+#p0.pid", condition = "#result != null")
            })
    List<SysDict> selectListSysDictForUpdate(SysDict sysDict)throws Exception;
    /**
     * 通过主键ID查询系统字典表对象
     * @param id 主键id
     * @return    
     */
    @Caching(
       cacheable = {
    @Cacheable(key = "'sysDict_'+#p0", unless="#result == null")},
       put = {
         @CachePut(key = "'sysDict_'+#p0", condition = "#result != null")
    })
    SysDict findSysDictById(String id)throws Exception;

    /**
     * 插入系统字典表
     * @param sysDict
     * @return   
     */
    @Caching(put = {
        @CachePut(key="'sysDict_'+#p0.code", condition = "#result != null"),
        @CachePut(key="'sysDict_'+#p0.name", condition = "#result != null"),
        @CachePut(key="'sysDict_'+#p0.pid", condition = "#result != null")
    })
    int insertSysDict(SysDict sysDict) throws Exception ;
    /**
     * 更新系统字典表
     * @param sysDict
     * @return     
     */
    @CachePut (key="'sysDict_'+#p0.code", condition = "#result>0")
    int updateSysDict(SysDict sysDict) throws Exception ;


}
